<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  

    <!--    <h:body>-->
    <ui:composition template="layout.xhtml">-->

        <ui:define name="corpo">
            <h:form id="incluir_form_entrada" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexSelo.xhtml')}" value="Selo" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('buscarEntradaSelo.xhtml')}" value="Pesquisar Selo" update="@form" immediate="true"/> >
                    <p:commandLink  value="Editar Selo" update="@form" immediate="true"/>
                </div>
                <p:panel header="Editar Entrada de Selo">
                    <p:messages id="msg"/>
                    <fieldset>
                        <legend>Cabeçalho da Entrada</legend>
                        <br/>
                        <h:panelGrid columns="2"  border="0" styleClass="textAlignRight" id="entrada" columnClasses="textAlignRight"> 
                            <h:outputText value="N° Nota :"/>
                            <p:inputText  id="notaselo" value="#{managerEditarEntradaSelo.entradaSelo.numeroNota}"/>

                            <h:outputText value="Fornecedor :"/>
                            <p:autoComplete id="fornecedor" value="#{managerEditarEntradaSelo.entradaSelo.fornecedor}" completeMethod="#{managerFornecedor.completeFornecedor}"  
                                            var="p" itemLabel="#{p.nome}" itemValue="#{p}" converter="fornecedorConverter" forceSelection="true" converterMessage="Erro, verifique o Fornecedor" minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Fornecedor' é obrigatório"> 
                                <p:ajax event="itemSelect" listener="#{managerEntrada.handleSelect}"/>                                        
                            </p:autoComplete>

                            <h:outputText value="Data da Nota :" /> 
                            <p:calendar value="#{managerEditarEntradaSelo.entradaSelo.dataNote}" label="Data" 
                                        size="15"  id="data_nota" mode="popup" showOn="both" pattern="dd/MM/yyyy" required="true" requiredMessage="O campo data entrada é obrigatorio"/>

                            <h:outputText value="Comentario :"/>
                            <p:inputTextarea  id="comentario" cols="70"  autoResize="true" value="#{managerEditarEntradaSelo.entradaSelo.comentario}"/>
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset id="cabecalhoSelos">
                        <legend>Entrada</legend> 
                        <h:panelGrid columns="6"   border="0" id="detalhes" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:outputText value="Tipo Selo :"/>
                            <p:autoComplete id="tipoSelo" panelStyle="width:250px !important;" effect="blind" value="#{managerEditarEntradaSelo.detalhe.tipoSelo}" size="20" completeMethod="#{managerTipoSelo.completeTipoSelo}"  
                                            var="p" itemLabel="#{p.nome}"   itemValue="#{p}" converter="tipoSeloConverter" forceSelection="true" 
                                            converterMessage="Erro, verifique o Tipo Selo" minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Tipo Selo' é obrigatório"> 
                                <p:column>  
                                    <table >
                                        <tr  style="height:20px; background-color: \##{p.corSelo.cor};">
                                            <td style="width: 20px;"></td>
                                        </tr>
                                    </table>
                                </p:column>
                                <p:column>  
                                    #{p.nome}
                                </p:column>  
                            </p:autoComplete>
                            <h:outputText value="Serie :"/>
                            <p:inputText value="#{managerEditarEntradaSelo.detalhe.serie}"/>
                            <h:outputText value="Preço :"/>
                            <p:inputText value="#{managerEditarEntradaSelo.detalhe.preco}" onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                <f:convertNumber type="currency" />
                            </p:inputText>
                            <h:outputText value="Numero inicial :" />
                            <p:inputText value="#{managerEditarEntradaSelo.detalhe.numIni}" onkeypress="jQuery(this).autoNumeric({aSep: '', aPad: false});"/>
                            <h:outputText value="Quantidade :"/>
                            <p:inputText value="#{managerEditarEntradaSelo.detalhe.qtd}" onkeypress="jQuery(this).autoNumeric({ aSep: '', aPad: false} );" />

                        </h:panelGrid>
                        <br/>
                        <p:row>
                            <center>
                                <p:commandButton  value="Adicionar" process="@form" icon="ui-icon-circle-plus" actionListener="#{managerEditarEntradaSelo.adicionarDetalhe()}" update="tabledetalhe, detalhes, msg"/>
                            </center>
                        </p:row>
                        <br/>
                        <p:dataTable id="tabledetalhe" var="detalhe" value="#{managerEditarEntradaSelo.detalhes}">
                            <f:facet name="header">
                                <h:outputText value="Detalhe da Entrada de Selos"/>
                            </f:facet>
                            <p:column headerText="Cor" style="width: 50px">
                                <h:outputText value=""/>
                                <table>
                                    <tr class="borderZero" style="height:30px; background-color: \##{detalhe.tipoSelo.corSelo.cor};">
                                        <td class="borderZero" style="width: 20px;"></td>
                                    </tr>
                                </table>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Tipo Selo"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.tipoSelo.nome}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Serie"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.serie}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Preço"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.preco}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Num Inicial"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.numIni}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Qtd"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.qtd}"/>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Num Final"/>
                                </f:facet>
                                <h:outputText value="#{detalhe.numFim}"/>
                            </p:column>
                            <p:column style="width: 60px">
                                <f:facet name="header">
                                    <h:outputText value="Opções"/>
                                </f:facet>
                                <p:commandButton style="float:left;" process="@this" title="Alterar" icon="editar" actionListener="#{managerEditarEntradaSelo.alterarDetalhe(detalhe)}"
                                       disabled="#{managerEditarEntradaSelo.naoPodeModificar(detalhe)}"  update="@form"/>
                                <p:commandButton style="float:left;" process="@this" title="Remover"  image="ui-icon-trash" 
                                                 disabled="#{managerEditarEntradaSelo.naoPodeModificar(detalhe)}" actionListener="#{managerEditarEntradaSelo.removerDetalhe(detalhe)}" update="@form"/>
                            </p:column>


                        </p:dataTable>
                    </fieldset>
                    <br/>
                    <div class="buttonAction">
                        <p:commandButton value="Atualizar"
                                         icon="ui-icon-disk"
                                         actionListener="#{managerEditarEntradaSelo.atualizar()}" 
                                         process="@this, entrada" update="@form" />
                        <p:commandButton value="Cancelar"
                                         icon="ui-icon-arrowreturnthick-1-w"
                                         actionListener="#{managerIndex.redirect('buscarEntradaSelo.xhtml')}" 
                                         process="@this, entrada" update="@form" />

                    </div>
                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>



</html>


